package com.bluedon.ism.commons.operationlog.entity;

import com.bluedon.ism.commons.entity.Account;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.persistence.*;
import java.util.Date;

import static javax.persistence.GenerationType.IDENTITY;

/**
 *
 * 操作日志
 */
@Entity
@Table(name = "OPERATELOG")
public class Operatelog implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	/**
	 * 操作类型 常量
	 */
	public static final Integer OPERATE_TYPE_ADD = 1;		 // 添加
	public static final Integer OPERATE_TYPE_UPDATE = 2;     // 修改
	public static final Integer OPERATE_TYPE_DELETE = 3;	 // 删除
	public static final Integer OPERATE_TYPE_SELECT = 4;	 // 查询
	
	
	
	private Long lid;
	private String moduleName;
	private String typeName;
	private String message;
	private Date createTime;
	private Account  account;
	private String className;
	private String errorMsg;
	private String methodName;
	
	private Long accountId;
    private String ipAddress;
	
	

	// Constructors

	/** default constructor */
	public Operatelog() {
	}

	/** full constructor */
	public Operatelog(String moduleName, String typeName, String message) {
		this.moduleName = moduleName;
		this.typeName = typeName;
		this.message = message;
	}
	/** full constructor */
	public Operatelog(String moduleName, String typeName, String message,
			Long userId, Date createTime) {
		this.moduleName = moduleName;
		this.typeName = typeName;
		this.message = message;
//		this.userId = userId;
		this.createTime = createTime;
	}

	
	
	public Operatelog(String moduleName, String typeName, String message,
			Date createTime, String className, String methodName, Long accountId) {
		super();
		this.moduleName = moduleName;
		this.typeName = typeName;
		this.message = message;
		this.createTime = createTime;
		this.className = className;
		this.methodName = methodName;
		this.accountId = accountId;
	}

	// Property accessors 
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "LID", unique = true, nullable = false, precision = 10, scale = 0)
	public Long getLid() {
		return this.lid;
	}

	public void setLid(Long lid) {
		this.lid = lid;
	}

	
	@Column(name="MODULE_NAME")
	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	@Column(name="TYPE_NAME")
	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	@Column(name = "MESSAGE", nullable = false, length = 1000)
	public String getMessage() {
		return this.message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@Column(name = "CREATE_TIME", nullable = false, length = 7)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ACCOUNT_ID",insertable = false, updatable = false)
	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	@Column(name="CLASS_NAME")
	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	@Column(name="ERROR_MSG")
	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	@Column(name="METHOD_NAME")
	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	@Column(name="ACCOUNT_ID")
	public Long getAccountId() {
		return accountId;
	}

	public void setAccountId(Long accountId) {
		this.accountId = accountId;
	}

    @Column(name="IP_ADDRESS")
    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }
}